# -*- coding:utf-8 -*-
from selenium import webdriver # 从selenium导入webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.options import Options
import json
import time

chrome_options = Options()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
# 不启动界面显示- linux下命令行模式必须启用
# chrome_options.add_argument('--headless')

driver = webdriver.Chrome(chrome_options=chrome_options)  # Optional argument, if not specified will search path.
driver.get('https://python.freelycode.com/contribution/translate/index') # 获取百度页面

driver.find_element_by_xpath('//*[@id="wxLoginBtn"]').click()

# # 显示等待
# try:
#     element = WebDriverWait(driver, 10).until(
#         EC.presence_of_element_located((By.XPATH, '/html/body/div[2]/div[2]/div[1]/ul/li[2]/a'))
#     )
# finally:
#     cookies = driver.get_cookies()
#     # time.sleep(5)
#     # driver.refresh('http://adnet.qq.com/index')

#     with open("cookies.txt", "w") as fp:
#         json.dump(cookies, fp)
time.sleep(5)

driver.find_elements_by_css_selector('body > div.container > div:nth-child(3) > div.col-sm-3 > ul > li.active > a').click()

# 关闭浏览器
driver.close()